define(function(require){

    require('../../../c/base/index');

    require('../../../c/nav/index');


    var token = {
        init : function() {
            //初始化菜单选中效果
            $(".fa-circle-o").each(function(){
                if($(this).parents("a").text() == "用户token清除"){
                    $(this).parents("a").parents("li").addClass("active");
                }
            });
            this.bindEvent();
            this.initValidator();
        },
        /**
         * 初始化表单验证
         */
        initValidator:function(){
            $('#mobileForm').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    sMobile: {
                        message: '手机号码输入错误',
                        validators: {
                            notEmpty: {
                                message: '手机号码不能为空'
                            },
                            phone: {
                                country: 'CN',
                                message: '请输入正确的电话格式'
                            }
                        }
                    }
                }
            });
        },
        /**
         * 初始化绑定事件
         */
        bindEvent : function() {
            var self = this;
            $("#get").click(function () {
                var obj = $("#mobileForm").data('bootstrapValidator');
                obj.validate();
                if (obj.isValid()) {
                    var mobile = $("#mobile").val();
                    self.clearToke(mobile);
                }
            });
        },

        clearToke : function(mobile) {
            CRM.request({
                url: CRM.getOuterUrl("/member/clearUserToken.do"),
                type: 'POST',
                "dataType": "json",
                contentType: "application/json",
                data: JSON.stringify({mobile:mobile}),
                success: function (req) {
                    CRM.showDialog(req.message);
                }
            });
        }
    };

    token.init();
});

